<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>前端eslint+prettier+lint-staged配置 | 西瓜蓬蓬的静谧庭院</title><meta name="keywords" content="前端配置,npm,eslint,prettier,lint-staged,eslintrc,eslintignore,prettierrc"><meta name="author" content="xiguapengpeng"><meta name="copyright" content="xiguapengpeng"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="前端eslint+prettier+lint-staged配置前提条件确保项目使用npm模块管理，若没有，根目录执行npm初始化生成package.json 1npm init  安装eslint开发环境解决代码质量问题：使用方式有可能有问题 (problematic patterns) 1npm install -D eslint eslint-plugin-vue  新建.eslintrc.j">
<meta property="og:type" content="article">
<meta property="og:title" content="前端eslint+prettier+lint-staged配置">
<meta property="og:url" content="https://xiguapengpeng.gitee.io/posts/df4b794e/index.html">
<meta property="og:site_name" content="西瓜蓬蓬的静谧庭院">
<meta property="og:description" content="前端eslint+prettier+lint-staged配置前提条件确保项目使用npm模块管理，若没有，根目录执行npm初始化生成package.json 1npm init  安装eslint开发环境解决代码质量问题：使用方式有可能有问题 (problematic patterns) 1npm install -D eslint eslint-plugin-vue  新建.eslintrc.j">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_1644837272.png">
<meta property="article:published_time" content="2022-02-18T07:58:01.295Z">
<meta property="article:modified_time" content="2022-03-26T06:53:36.356Z">
<meta property="article:author" content="xiguapengpeng">
<meta property="article:tag" content="eslint">
<meta property="article:tag" content="prettier">
<meta property="article:tag" content="lint-staged">
<meta property="article:tag" content="npm">
<meta property="article:tag" content="eslintrc">
<meta property="article:tag" content="eslintignore">
<meta property="article:tag" content="prettierrc">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_1644837272.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://xiguapengpeng.gitee.io/posts/df4b794e/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="google-site-verification" content="CMfiiaCCwQ90-u9hmlL-7VUq-v_zt9rhyg1Ke1A7ia4"/><meta name="baidu-site-verification" content="code-Wsugu6NsqF"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?0b83b38ff142c9faea5f5987d7c6f3f0";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '前端eslint+prettier+lint-staged配置',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-03-26 14:53:36'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.0.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://gitee.com/xiguapengpeng/imgtu/raw/master/blog/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">34</div></a></div><div class="data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">122</div></a></div><div class="data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-compass"></i><span> 导航</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 豆瓣</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page child" href="/game/"><i class="fa-fw fas fa-gamepad"></i><span> 游戏</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_1644837272.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">西瓜蓬蓬的静谧庭院</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-compass"></i><span> 导航</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 豆瓣</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page child" href="/game/"><i class="fa-fw fas fa-gamepad"></i><span> 游戏</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">前端eslint+prettier+lint-staged配置</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-02-18T07:58:01.295Z" title="发表于 2022-02-18 15:58:01">2022-02-18</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-03-26T06:53:36.356Z" title="更新于 2022-03-26 14:53:36">2022-03-26</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/frontend/">frontend</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">584</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>2分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="前端eslint+prettier+lint-staged配置"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="前端eslint-prettier-lint-staged配置"><a href="#前端eslint-prettier-lint-staged配置" class="headerlink" title="前端eslint+prettier+lint-staged配置"></a>前端eslint+prettier+lint-staged配置</h1><h2 id="前提条件"><a href="#前提条件" class="headerlink" title="前提条件"></a>前提条件</h2><p>确保项目使用<code>npm</code>模块管理，若没有，根目录执行<code>npm</code>初始化生成<code>package.json</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm init</span><br></pre></td></tr></table></figure>

<h2 id="安装eslint开发环境"><a href="#安装eslint开发环境" class="headerlink" title="安装eslint开发环境"></a>安装eslint开发环境</h2><p>解决代码质量问题：使用方式有可能有问题 (<code>problematic patterns</code>)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -D eslint eslint-plugin-vue</span><br></pre></td></tr></table></figure>

<p>新建.eslintrc.js配置文件（仅做参考，自行补充）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">module.exports = &#123;</span><br><span class="line">  env: &#123;</span><br><span class="line">    browser: true,</span><br><span class="line">    es2021: true,</span><br><span class="line">    node: true</span><br><span class="line">  &#125;,</span><br><span class="line">  extends: [</span><br><span class="line">    &#x27;eslint:recommended&#x27;,</span><br><span class="line">    &#x27;plugin:vue/recommended&#x27;,</span><br><span class="line">    // &#x27;plugin:vue/vue3-recommended&#x27;, // Use this if you are using Vue.js 3.x.</span><br><span class="line">    &#x27;plugin:prettier/recommended&#x27;</span><br><span class="line">  ],</span><br><span class="line">  parserOptions: &#123;</span><br><span class="line">    ecmaVersion: 13,</span><br><span class="line">    sourceType: &#x27;module&#x27;</span><br><span class="line">  &#125;,</span><br><span class="line">  rules: &#123;</span><br><span class="line">  	// 自定义规则</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>新建<code>.eslintignore</code>指定<code>eslint</code>忽略文件和目录（仅做参考，自行补充）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">node_modules</span><br><span class="line">static</span><br><span class="line">dist</span><br><span class="line">uni_modules</span><br></pre></td></tr></table></figure>

<h2 id="安装prettier开发环境"><a href="#安装prettier开发环境" class="headerlink" title="安装prettier开发环境"></a>安装prettier开发环境</h2><p>解决代码风格问题：风格不符合一定规则 (<code>doesn’t adhere to certain style guidelines</code>)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -D prettier eslint-plugin-prettier eslint-config-prettier</span><br></pre></td></tr></table></figure>

<p>新建<code>.prettierrc</code>配置文件（仅做参考，自行补充）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;semi&quot;: false,</span><br><span class="line">  &quot;singleQuote&quot;: true,</span><br><span class="line">  &quot;endOfLine&quot;: &quot;auto&quot;,</span><br><span class="line">  &quot;trailingComma&quot;: &quot;none&quot;,</span><br><span class="line">  &quot;quoteProps&quot;: &quot;preserve&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="安装lint-staged开发环境"><a href="#安装lint-staged开发环境" class="headerlink" title="安装lint-staged开发环境"></a>安装lint-staged开发环境</h2><p>用于对<code>Git</code>暂存区中的文件执行代码检测，结合<code>husky</code>用到<code>pre-commit</code>这个<code>hook</code>，在执行<code>commit</code>之前，可以运行一些自定义操作</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -D husky lint-staged</span><br></pre></td></tr></table></figure>

<p>在<code>package.json</code>文件中增加节点（仅做参考，自行补充）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&quot;husky&quot;: &#123;</span><br><span class="line">    &quot;hooks&quot;: &#123;</span><br><span class="line">		&quot;pre-commit&quot;: &quot;lint-staged&quot;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;,</span><br><span class="line">&quot;lint-staged&quot;: &#123;</span><br><span class="line">	&quot;src/**/*.&#123;js,vue&#125;&quot;: [</span><br><span class="line">		&quot;eslint --fix&quot;,</span><br><span class="line">		&quot;git add&quot;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="主流IDE插件配置"><a href="#主流IDE插件配置" class="headerlink" title="主流IDE插件配置"></a>主流IDE插件配置</h2><h3 id="VSCode"><a href="#VSCode" class="headerlink" title="VSCode"></a>VSCode</h3><p>应用商店中搜索扩展插件</p>
<ul>
<li>ESLint</li>
<li>Prettier - Code formatter</li>
<li>Vetur</li>
</ul>
<p>任意插件右键选择扩展设置，找到在<code>setting.json</code>中打开</p>
<p>增加以下内容</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&quot;editor.formatOnSave&quot;: false,</span><br><span class="line">&quot;editor.tabSize&quot;: 2,</span><br><span class="line">&quot;editor.autoClosingQuotes&quot;: &quot;always&quot;,</span><br><span class="line">&quot;javascript.preferences.quoteStyle&quot;: &quot;single&quot;,</span><br><span class="line">&quot;vetur.validation.template&quot;: false,</span><br><span class="line">&quot;eslint.enable&quot;: true,</span><br><span class="line">&quot;eslint.run&quot;: &quot;onType&quot;,</span><br><span class="line">&quot;editor.codeActionsOnSave&quot;: &#123;</span><br><span class="line">    // For ESLint</span><br><span class="line">    &quot;source.fixAll.eslint&quot;: true,</span><br><span class="line">    // For TSLint</span><br><span class="line">    &quot;source.fixAll.tslint&quot;: true,</span><br><span class="line">    // For Stylelint</span><br><span class="line">    &quot;source.fixAll.stylelint&quot;: true</span><br><span class="line">&#125;,</span><br><span class="line">&quot;eslint.options&quot;: &#123;</span><br><span class="line">	&quot;extensions&quot;: [&quot;.js&quot;, &quot;.ts&quot;, &quot;.vue&quot;]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="HbuilderX"><a href="#HbuilderX" class="headerlink" title="HbuilderX"></a>HbuilderX</h3><p>插件市场搜索eslint安装</p>
<ul>
<li>eslint-plugin-vue</li>
<li>eslint-js</li>
</ul>
<p>找到两个插件的配置，将以下选项打勾</p>
<ul>
<li><p><input checked="" disabled="" type="checkbox"> 
保存时自动修复</p>
</li>
<li><p><input checked="" disabled="" type="checkbox"> 
启用实时校验</p>
</li>
</ul>
<h3 id="WebStorm"><a href="#WebStorm" class="headerlink" title="WebStorm"></a>WebStorm</h3><p>打开<code>Settings/Preferences</code>对话框(Ctrl+Alt+S)，进入<code>Languages and Frameworks</code>| <code>JavaScript</code> |<code>Code Quality Tools</code>| <code>ESLint</code>，并选择<code>Run ESLint——fix on save</code>复选框</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">xiguapengpeng</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://xiguapengpeng.gitee.io/posts/df4b794e/">https://xiguapengpeng.gitee.io/posts/df4b794e/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://xiguapengpeng.gitee.io" target="_blank">西瓜蓬蓬的静谧庭院</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/eslint/">eslint</a><a class="post-meta__tags" href="/tags/prettier/">prettier</a><a class="post-meta__tags" href="/tags/lint-staged/">lint-staged</a><a class="post-meta__tags" href="/tags/npm/">npm</a><a class="post-meta__tags" href="/tags/eslintrc/">eslintrc</a><a class="post-meta__tags" href="/tags/eslintignore/">eslintignore</a><a class="post-meta__tags" href="/tags/prettierrc/">prettierrc</a></div><div class="post_share"><div class="social-share" data-image="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_1644837272.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://gitee.com/xiguapengpeng/imgtu/raw/master/blog/wx_reward.jpg" target="_blank"><img class="post-qr-code-img" src="https://gitee.com/xiguapengpeng/imgtu/raw/master/blog/wx_reward.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/posts/ece54ef9/"><img class="prev-cover" src="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_20220217192410.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">hexo-butterfly主题博客搭建部署</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/ece54ef9/" title="hexo-butterfly主题博客搭建部署"><img class="cover" src="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_20220217192410.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-02-18</div><div class="title">hexo-butterfly主题博客搭建部署</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://gitee.com/xiguapengpeng/imgtu/raw/master/blog/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">xiguapengpeng</div><div class="author-info__description">分享知识、勤做笔记</div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">34</div></a></div><div class="card-info-data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">122</div></a></div><div class="card-info-data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xiguapengpeng"><i class="fab fa-heart"></i><span>个人仓库</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">若时光逝却，就珍存过往</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%89%8D%E7%AB%AFeslint-prettier-lint-staged%E9%85%8D%E7%BD%AE"><span class="toc-number">1.</span> <span class="toc-text">前端eslint+prettier+lint-staged配置</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%89%8D%E6%8F%90%E6%9D%A1%E4%BB%B6"><span class="toc-number">1.1.</span> <span class="toc-text">前提条件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85eslint%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="toc-number">1.2.</span> <span class="toc-text">安装eslint开发环境</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85prettier%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="toc-number">1.3.</span> <span class="toc-text">安装prettier开发环境</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85lint-staged%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="toc-number">1.4.</span> <span class="toc-text">安装lint-staged开发环境</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BB%E6%B5%81IDE%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE"><span class="toc-number">1.5.</span> <span class="toc-text">主流IDE插件配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#VSCode"><span class="toc-number">1.5.1.</span> <span class="toc-text">VSCode</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#HbuilderX"><span class="toc-number">1.5.2.</span> <span class="toc-text">HbuilderX</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#WebStorm"><span class="toc-number">1.5.3.</span> <span class="toc-text">WebStorm</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/bd6c95d5/" title="Windows10安装java环境"><img src="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_20230131095714.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Windows10安装java环境"/></a><div class="content"><a class="title" href="/posts/bd6c95d5/" title="Windows10安装java环境">Windows10安装java环境</a><time datetime="2023-01-31T01:59:34.432Z" title="发表于 2023-01-31 09:59:34">2023-01-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/fdc8614/" title="Java8到Java17之间的主要特性描述"><img src="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_20230130095755.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Java8到Java17之间的主要特性描述"/></a><div class="content"><a class="title" href="/posts/fdc8614/" title="Java8到Java17之间的主要特性描述">Java8到Java17之间的主要特性描述</a><time datetime="2023-01-30T01:59:04.252Z" title="发表于 2023-01-30 09:59:04">2023-01-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/9542a1f7/" title="CentOS7安装OpenSSL环境"><img src="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_20230114172144.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="CentOS7安装OpenSSL环境"/></a><div class="content"><a class="title" href="/posts/9542a1f7/" title="CentOS7安装OpenSSL环境">CentOS7安装OpenSSL环境</a><time datetime="2023-01-14T09:34:08.209Z" title="发表于 2023-01-14 17:34:08">2023-01-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/da432f73/" title="OpenSSL生成证书"><img src="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_20230114172959.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="OpenSSL生成证书"/></a><div class="content"><a class="title" href="/posts/da432f73/" title="OpenSSL生成证书">OpenSSL生成证书</a><time datetime="2023-01-14T09:33:46.203Z" title="发表于 2023-01-14 17:33:46">2023-01-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/e0523c/" title="CentOS7安装cmake工具"><img src="http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_20221217113021.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="CentOS7安装cmake工具"/></a><div class="content"><a class="title" href="/posts/e0523c/" title="CentOS7安装cmake工具">CentOS7安装cmake工具</a><time datetime="2022-12-17T03:39:03.528Z" title="发表于 2022-12-17 11:39:03">2022-12-17</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('http://xiguapengpeng.gitee.io/imgtu/blog/post_cover_1644837272.png')"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2023 By xiguapengpeng</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">醉后不知天在水，满船清梦压星河。</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><div class="aplayer no-destroy" data-id="60198" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true"></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false},"log":false});</script></body></html>